package com.pattern.structure.composite;

/**
 * @author yangguanzan
 * @date 7/2/22
 * @description
 */
public class CompositeLeaf implements CompositeComponent {

    private String name;

    public CompositeLeaf(String name){
        this.name = name;
    }

    /**
     * 加Deprecated注解，利用编译器警告该方法已失效
     * 直接使用则直接抛出不支持执行的异常
     * @param treeNode
     */
    @Deprecated
    @Override
    public void add(CompositeComponent treeNode) {
        throw new UnsupportedOperationException();
    }

    @Override
    public void operation() {
        System.out.println(name+ " CompositeLeaf doing");
    }

    @Deprecated
    @Override
    public void remove(CompositeComponent leaf2) {
        throw new UnsupportedOperationException();
    }

    @Deprecated
    @Override
    public CompositeComponent getChild(int i) {
        throw new UnsupportedOperationException();
    }


    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }
}
